const modules = import.meta.glob('./modules/*.ts', { eager: true })

type ApiModules = { [key: string]: any }

const createApiModules = () => {
  const apiModules: ApiModules = {}
  for (const modulePath in modules) {
    if (Object.prototype.hasOwnProperty.call(modules, modulePath)) {
      const module = (modules[modulePath] as any).default
      const paths = modulePath.split('/')
      const fileName = paths[paths.length - 1]
      const moduleName = fileName.split('.')[0]
      apiModules[moduleName] = module
    }
  }
  console.debug(`注册api模块<${Object.keys(apiModules).length}个>`)
  return apiModules
}

const apiModules = createApiModules()
export default apiModules
